package com.qimu.saiyou.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qimu.saiyou.common.ErrorCode;
import com.qimu.saiyou.constant.CommonConstant;
import com.qimu.saiyou.exception.BusinessException;
import com.qimu.saiyou.exception.ThrowUtils;
import com.qimu.saiyou.mapper.CompeteExamMapper;
import com.qimu.saiyou.model.dto.competeexam.CompeteExamQueryRequest;
import com.qimu.saiyou.model.dto.useranswer.UserAnswer;
import com.qimu.saiyou.model.dto.useranswer.UserPaperAnswerRequest;
import com.qimu.saiyou.model.entity.*;
import com.qimu.saiyou.model.vo.UserPaperVo;
import com.qimu.saiyou.mq.UserPaperendMessageProducer;
import com.qimu.saiyou.service.*;
import com.qimu.saiyou.utils.SqlUtils;
import javafx.util.Pair;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: FeiXiang
 * @description 针对表【compete_exam(考试)】的数据库操作Service实现
 * @createDate 2024-02-28 20:36:14
 */
@Slf4j
@Service
public class CompeteExamServiceImpl extends ServiceImpl<CompeteExamMapper, CompeteExam>
        implements CompeteExamService {
    @Resource
    private UserPaperAnswerService userPaperAnswerService;
    @Resource
    private UserService userService;
    @Resource
    private PaperQuestionService paperQuestionService;
    @Resource
    private QuestionService questionService;
    @Resource
    private ExamPaperService examPaperService;
    @Resource
    private QuestionAnswerService questionAnswerService;
    @Resource
    private UserPaperService userPaperService;
    @Resource
    private UserPaperendMessageProducer userPaperendMessageProducer;

    @Override
    public void validCompeteExam(CompeteExam competeExam, boolean add) {
        if (competeExam == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        Long id = competeExam.getId();
        String examName = competeExam.getExamName();
        Long paperId = competeExam.getPaperId();
        String description = competeExam.getDescription();
        Long totalTime = competeExam.getTotalTime();
        Long qualifyScore = competeExam.getQualifyScore();
        Long competitionId = competeExam.getCompetitionId();

        // 创建时，参数不能为空
        if (add) {
            ThrowUtils.throwIf(StringUtils.isAnyBlank(examName), ErrorCode.PARAMS_ERROR, "考试名称不能为空");
            ThrowUtils.throwIf(ObjectUtils.isEmpty(paperId) && paperId <= 0, ErrorCode.PARAMS_ERROR, "请选择试卷");
            ThrowUtils.throwIf(ObjectUtils.isEmpty(totalTime), ErrorCode.PARAMS_ERROR, "考试时长不能为空");
            ThrowUtils.throwIf(ObjectUtils.isEmpty(totalTime), ErrorCode.PARAMS_ERROR, "考试时长不能为空");
        }
        // 有参数则校验
        if (StringUtils.isNotBlank(examName) && examName.length() > 40) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "队名过长");
        }
        if (StringUtils.isNotBlank(description) && description.length() > 140) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "描述内容过长");
        }
        if (ObjectUtils.isNotEmpty(qualifyScore) && qualifyScore <= 0) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "及格分数需要大于0");
        }

        if (ObjectUtils.isNotEmpty(paperId) && paperId <= 0) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "请选择试卷");
        }

        if (ObjectUtils.isNotEmpty(totalTime) && totalTime <= 0) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "考试时长过短");
        }
    }

    @Override
    public QueryWrapper<CompeteExam> getQueryWrapper(CompeteExamQueryRequest competeExamQueryRequest) {
        QueryWrapper<CompeteExam> queryWrapper = new QueryWrapper<>();
        if (competeExamQueryRequest == null) {
            return queryWrapper;
        }
        Long id = competeExamQueryRequest.getId();
        String searchText = competeExamQueryRequest.getSearchText();
        int current = competeExamQueryRequest.getCurrent();
        int pageSize = competeExamQueryRequest.getPageSize();
        String state = competeExamQueryRequest.getState();
        String sortField = competeExamQueryRequest.getSortField();
        String sortOrder = competeExamQueryRequest.getSortOrder();

        // 拼接查询条件
        if (StringUtils.isNotBlank(searchText)) {
            queryWrapper.and(qw -> qw.lambda().like(CompeteExam::getExamName, searchText).or()
                    .like(CompeteExam::getDescription, searchText));
        }

        queryWrapper.eq(ObjectUtils.isNotEmpty(id), "id", id);
        queryWrapper.eq(ObjectUtils.isNotEmpty(state), "state", state);
        queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
                sortField);
        return queryWrapper;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public UserPaper startTheExam(User loginUser, CompeteExam competeExam) {
        Long paperId = competeExam.getPaperId();
        ExamPaper examPaper = examPaperService.getById(paperId);
        ThrowUtils.throwIf(examPaper == null, ErrorCode.NOT_FOUND_ERROR);
        // 获取试卷题目
        List<PaperQuestion> paperQuestionList = paperQuestionService.lambdaQuery().eq(PaperQuestion::getPaperId, examPaper.getId()).list();
        List<UserPaperAnswer> userPaperAnswers = new ArrayList<>();
        // 组卷考试
        UserPaper newUserPaper = new UserPaper();
        newUserPaper.setExamId(competeExam.getId());
        newUserPaper.setUserId(loginUser.getId());
        newUserPaper.setState("open");
        newUserPaper.setCompetitionId(competeExam.getCompetitionId());
        newUserPaper.setTotalTime(competeExam.getTotalTime());
        boolean save = userPaperService.save(newUserPaper);
        ThrowUtils.throwIf(!save, ErrorCode.NOT_FOUND_ERROR, "参加考试失败，请重试");
        for (PaperQuestion paperQuestion : paperQuestionList) {
            Long questionId = paperQuestion.getQuestionId();
            Question question = questionService.getById(questionId);
            if (question == null) {
                throw new BusinessException(ErrorCode.NOT_FOUND_ERROR, "题目不存在");
            }
            if (question.getType() != 2) {
                UserPaperAnswer userPaperAnswer = new UserPaperAnswer();
                userPaperAnswer.setQuestionId(question.getId());
                userPaperAnswer.setUserPaperId(newUserPaper.getId());
                userPaperAnswers.add(userPaperAnswer);
            } else {
                questionAnswerService.lambdaQuery().eq(QuestionAnswer::getQuestionId, questionId).list().forEach(questionAnswer -> {
                    UserPaperAnswer userPaperAnswer = new UserPaperAnswer();
                    userPaperAnswer.setQuestionId(question.getId());
                    userPaperAnswer.setUserPaperId(newUserPaper.getId());
                    userPaperAnswers.add(userPaperAnswer);
                });
            }
        }
        boolean saveBatch = userPaperAnswerService.saveBatch(userPaperAnswers);
        ThrowUtils.throwIf(!saveBatch, ErrorCode.NOT_FOUND_ERROR, "参加考试失败，请重试");

        Long totalTime = competeExam.getTotalTime();
        long totalMilliseconds = totalTime * 60 * 1000;
        userPaperendMessageProducer.sendMessage(newUserPaper.getId().toString(), (int) totalMilliseconds);
        // todo rabbmitmq添加考试结束时间
        return newUserPaper;
    }

    // @Override
    // @Transactional(rollbackFor = Exception.class)
    // public boolean saveAnswer(User loginUser, UserPaperAnswerRequest userPaperAnswerRequest) {
    //     Long id = userPaperAnswerRequest.getId();
    //     UserPaper userPaper = userPaperService.getById(id);
    //     if (ObjectUtils.isEmpty(userPaper)) {
    //         throw new BusinessException(ErrorCode.OPERATION_ERROR, "考试不存在");
    //     }
    //
    //     if (("finish".equals(userPaper.getState()) || "submit".equals(userPaper.getState()))) {
    //         throw new BusinessException(ErrorCode.OPERATION_ERROR, "您已参加过或已提交该考试");
    //     }
    //
    //     List<UserPaperAnswer> userPaperAnswers = userPaperAnswerService.lambdaQuery()
    //             .eq(UserPaperAnswer::getUserPaperId, userPaper.getId())
    //             .list();
    //     List<UserAnswer> userAnswerList = userPaperAnswerRequest.getUserAnswerList();
    //     HashMap<Long, UserAnswer> longUserAnswerHashMap = new HashMap<>();
    //     List<UserPaperAnswer> userNewAnswerList = new ArrayList<>();
    //     if (CollUtil.isNotEmpty(userAnswerList)) {
    //         for (UserAnswer userAnswer : userAnswerList) {
    //             longUserAnswerHashMap.put(userAnswer.getQuestionId(), userAnswer);
    //         }
    //     }
    //     if (CollUtil.isNotEmpty(longUserAnswerHashMap)) {
    //         for (UserPaperAnswer userPaperAnswer : userPaperAnswers) {
    //             UserAnswer userAnswer = longUserAnswerHashMap.get(userPaperAnswer.getQuestionId());
    //             if (userAnswer == null) {
    //                 continue;
    //             }
    //             Long answerId = userAnswer.getAnswerId();
    //             String subjectiveAnswer = userAnswer.getSubjectiveAnswer();
    //             userPaperAnswer.setAnswerId(answerId);
    //             userPaperAnswer.setSubjectiveAnswer(subjectiveAnswer);
    //             userNewAnswerList.add(userPaperAnswer);
    //         }
    //     }
    //     return userPaperAnswerService.updateBatchById(userNewAnswerList);
    // }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveAnswer(User loginUser, UserPaperAnswerRequest userPaperAnswerRequest) {
        Long id = userPaperAnswerRequest.getId();
        UserPaper userPaper = userPaperService.getById(id);
        if (ObjectUtils.isEmpty(userPaper)) {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "考试不存在");
        }
        if (("finish".equals(userPaper.getState()) || "submit".equals(userPaper.getState()))) {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "您已参加过或已提交该考试");
        }
        List<UserPaperAnswer> userPaperAnswers = userPaperAnswerService.lambdaQuery()
                .eq(UserPaperAnswer::getUserPaperId, userPaper.getId())
                .list();
        List<UserAnswer> userAnswerList = userPaperAnswerRequest.getUserAnswerList();
        List<UserPaperAnswer> userNewAnswerList = new ArrayList<>();
        List<Pair<Long, UserAnswer>> cheackBoxUserAnswer = new ArrayList<>();
        List<Pair<Long, UserAnswer>> radioUserAnswer = new ArrayList<>();

        if (CollUtil.isNotEmpty(userAnswerList)) {
            for (UserAnswer userAnswer : userAnswerList) {
                Long questionId = userAnswer.getQuestionId();
                Question question = questionService.getById(questionId);
                if (question == null) {
                    throw new BusinessException(ErrorCode.NOT_FOUND_ERROR, "题目不存在");
                }
                if (question.getType() == 2) {
                    cheackBoxUserAnswer.add(new Pair<>(userAnswer.getQuestionId(), userAnswer));
                } else {
                    radioUserAnswer.add(new Pair<>(userAnswer.getQuestionId(), userAnswer));
                }
            }
        }
        if (CollUtil.isNotEmpty(radioUserAnswer)) {
            for (int i = 0; i < radioUserAnswer.size(); i++) {
                Pair<Long, UserAnswer> longUserAnswerPair = radioUserAnswer.get(i);
                Long questionId = longUserAnswerPair.getKey();
                UserAnswer userAnswer = longUserAnswerPair.getValue();
                if (userAnswer == null) {
                    continue;
                }
                Long answerId = userAnswer.getAnswerId();
                String subjectiveAnswer = userAnswer.getSubjectiveAnswer();
                List<UserPaperAnswer> userPaperAnswerList = userPaperAnswers.stream().filter(userPaperAnswer -> userPaperAnswer.getQuestionId().equals(questionId)).collect(Collectors.toList());
                UserPaperAnswer userPaperAnswer = null;
                userPaperAnswer = userPaperAnswerList.get(0);
                // }
                if (userPaperAnswer == null) {
                    continue;
                }
                userPaperAnswer.setAnswerId(answerId);
                userPaperAnswer.setSubjectiveAnswer(subjectiveAnswer);
                userNewAnswerList.add(userPaperAnswer);
            }
        }
        if (CollUtil.isNotEmpty(cheackBoxUserAnswer)) {
            for (int i = 0; i < cheackBoxUserAnswer.size(); i++) {
                Pair<Long, UserAnswer> longUserAnswerPair = cheackBoxUserAnswer.get(i);
                Long questionId = longUserAnswerPair.getKey();
                UserAnswer userAnswer = longUserAnswerPair.getValue();
                if (userAnswer == null) {
                    continue;
                }
                Long answerId = userAnswer.getAnswerId();
                String subjectiveAnswer = userAnswer.getSubjectiveAnswer();
                List<UserPaperAnswer> userPaperAnswerList = userPaperAnswers.stream().filter(userPaperAnswer -> userPaperAnswer.getQuestionId().equals(questionId)).collect(Collectors.toList());
                UserPaperAnswer userPaperAnswer = null;
                userPaperAnswer = userPaperAnswerList.get(i);
                if (userPaperAnswer == null) {
                    continue;
                }
                userPaperAnswer.setAnswerId(answerId);
                userPaperAnswer.setSubjectiveAnswer(subjectiveAnswer);
                userNewAnswerList.add(userPaperAnswer);
            }
        }
        return userPaperAnswerService.updateBatchById(userNewAnswerList);

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public UserPaperVo submitPaper(User loginUser, UserPaperAnswerRequest userPaperAnswerRequest) {
        Long id = userPaperAnswerRequest.getId();
        UserPaper userPaper = userPaperService.getById(id);
        if (ObjectUtils.isEmpty(userPaper)) {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "考试不存在");
        }
        if (("submit".equals(userPaper.getState()))) {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "您已提交过该考试");
        }

        CompeteExam competeExam = this.getById(userPaper.getExamId());
        if (competeExam == null) {
            log.error("试卷保存失败");
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "试卷保存失败");
        }
        Long paperId = competeExam.getPaperId();
        ExamPaper examPaper = examPaperService.getById(paperId);
        if (examPaper == null) {
            log.error("试卷保存失败");
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "试卷保存失败");
        }

        // todo 结算
        List<UserPaperAnswer> newUserPaperAnswer = userPaperAnswerService.lambdaQuery()
                .eq(UserPaperAnswer::getUserPaperId, userPaper.getId())
                .list();

        newUserPaperAnswer = newUserPaperAnswer.stream().filter(a -> a.getAnswerId() != null).collect(Collectors.toList());
        long sum = 0;
        for (UserPaperAnswer userPaperAnswer : newUserPaperAnswer) {
            Long questionId = userPaperAnswer.getQuestionId();
            Question question = questionService.getById(questionId);
            if (question == null) {
                continue;
            }
            PaperQuestion paperQuestion = paperQuestionService.lambdaQuery()
                    .eq(PaperQuestion::getQuestionId, question.getId())
                    .eq(PaperQuestion::getPaperId, competeExam.getPaperId()).one();
            List<QuestionAnswer> correctAnswers = questionAnswerService.lambdaQuery().eq(QuestionAnswer::getIsRight, 1).eq(QuestionAnswer::getQuestionId, question.getId()).list();
            List<Long> correctAnswerIds = correctAnswers.stream().map(QuestionAnswer::getId).sorted().collect(Collectors.toList());

            if (question.getType() == 2) {
                // 获取题目的正确答案列表
                // 获取用户的答案列表
                List<UserPaperAnswer> userAnswers = newUserPaperAnswer.stream().filter(a -> a.getQuestionId().equals(question.getId())).collect(Collectors.toList());
                // 将答案ID排序并比较
                List<Long> userAnswerIds = userAnswers.stream().map(UserPaperAnswer::getAnswerId).sorted().collect(Collectors.toList());

                // 如果答案完全匹配，则加分
                if (correctAnswerIds.equals(userAnswerIds)) {
                    sum += paperQuestion.getScore();
                }
            } else {
                if (correctAnswerIds.contains(userPaperAnswer.getAnswerId())) {
                    sum += paperQuestion.getScore();
                }
            }
        }
        userPaper.setTotalScore(sum);
        userPaper.setState("submit");
        userPaperService.updateById(userPaper);

        Calendar cl = Calendar.getInstance();
        cl.setTimeInMillis(System.currentTimeMillis());
        int userTime = (int) ((System.currentTimeMillis() - userPaper.getCreateTime().getTime()) / 1000 / 60);
        UserPaperVo userPaperVo = UserPaperVo.objToVo(userPaper);
        userPaperVo.setUserTime(userTime);
        return userPaperVo;
    }

    // @Override
    // @Transactional(rollbackFor = Exception.class)
    // public UserPaperVo submitPaper(User loginUser, UserPaperAnswerRequest userPaperAnswerRequest) {
    //     Long id = userPaperAnswerRequest.getId();
    //     UserPaper userPaper = userPaperService.getById(id);
    //     if (ObjectUtils.isEmpty(userPaper)) {
    //         throw new BusinessException(ErrorCode.OPERATION_ERROR, "考试不存在");
    //     }
    //     if (("submit".equals(userPaper.getState()))) {
    //         throw new BusinessException(ErrorCode.OPERATION_ERROR, "您已提交过该考试");
    //     }
    //
    //     CompeteExam competeExam = this.getById(userPaper.getExamId());
    //     if (competeExam == null) {
    //         log.error("试卷保存失败");
    //         throw new BusinessException(ErrorCode.OPERATION_ERROR, "试卷保存失败");
    //     }
    //     Long paperId = competeExam.getPaperId();
    //     ExamPaper examPaper = examPaperService.getById(paperId);
    //     if (examPaper == null) {
    //         log.error("试卷保存失败");
    //         throw new BusinessException(ErrorCode.OPERATION_ERROR, "试卷保存失败");
    //     }
    //
    //     List<UserPaperAnswer> userPaperAnswers = userPaperAnswerService.lambdaQuery()
    //             .eq(UserPaperAnswer::getUserPaperId, userPaper.getId())
    //             .list();
    //     List<UserAnswer> userAnswerList = userPaperAnswerRequest.getUserAnswerList();
    //     List<UserPaperAnswer> userNewAnswerList = new ArrayList<>();
    //     List<Pair<Long, UserAnswer>> longUserAnswer = new ArrayList<>();
    //
    //     if (CollUtil.isNotEmpty(userAnswerList)) {
    //         for (UserAnswer userAnswer : userAnswerList) {
    //             longUserAnswer.add(new Pair<>(userAnswer.getQuestionId(), userAnswer));
    //         }
    //     }
    //     if (CollUtil.isNotEmpty(longUserAnswer)) {
    //         for (int i = 0; i < longUserAnswer.size(); i++) {
    //             Pair<Long, UserAnswer> longUserAnswerPair = longUserAnswer.get(i);
    //             Long questionId = longUserAnswerPair.getKey();
    //             Question question = questionService.getById(questionId);
    //             if (question == null) {
    //                 throw new BusinessException(ErrorCode.NOT_FOUND_ERROR, "题目不存在");
    //             }
    //             UserAnswer userAnswer = longUserAnswerPair.getValue();
    //             if (userAnswer == null) {
    //                 continue;
    //             }
    //             Long answerId = userAnswer.getAnswerId();
    //             String subjectiveAnswer = userAnswer.getSubjectiveAnswer();
    //             List<UserPaperAnswer> userPaperAnswerList = userPaperAnswers.stream().filter(userPaperAnswer -> userPaperAnswer.getQuestionId().equals(questionId)).collect(Collectors.toList());
    //             UserPaperAnswer userPaperAnswer = null;
    //             if (question.getType() == 2) {
    //                 userPaperAnswer = userPaperAnswerList.get(i);
    //             } else {
    //                 userPaperAnswer = userPaperAnswerList.get(0);
    //             }
    //             if (userPaperAnswer == null) {
    //                 continue;
    //             }
    //             userPaperAnswer.setAnswerId(answerId);
    //             userPaperAnswer.setSubjectiveAnswer(subjectiveAnswer);
    //             userNewAnswerList.add(userPaperAnswer);
    //         }
    //     }
    //     userPaperAnswerService.updateBatchById(userNewAnswerList);
    //
    //     List<UserPaperAnswer> userPaperAnswer2 = userPaperAnswerService.lambdaQuery()
    //             .eq(UserPaperAnswer::getUserPaperId, userPaper.getId())
    //             .list();
    //     List<Pair<Long, UserAnswer>> longUserAnswer2 = new ArrayList<>();
    //     List<UserAnswer> userAnswerList2 = userPaperAnswerRequest.getUserAnswerList();
    //     if (CollUtil.isNotEmpty(userAnswerList2)) {
    //         for (UserAnswer userAnswer : userAnswerList2) {
    //             longUserAnswer2.add(new Pair<>(userAnswer.getQuestionId(), userAnswer));
    //         }
    //     }
    //
    //     long sum = 0;
    //     if (!longUserAnswer2.isEmpty()) {
    //         for (int i = 0; i < longUserAnswer2.size(); i++) {
    //             Pair<Long, UserAnswer> longUserAnswerPair = longUserAnswer2.get(i);
    //             Long questionId = longUserAnswerPair.getKey();
    //             Question question = questionService.getById(questionId);
    //             if (question == null) {
    //                 throw new BusinessException(ErrorCode.NOT_FOUND_ERROR, "题目不存在");
    //             }
    //             UserAnswer userAnswer = longUserAnswerPair.getValue();
    //             if (userAnswer == null) {
    //                 continue;
    //             }
    //             PaperQuestion paperQuestion = paperQuestionService.lambdaQuery()
    //                     .eq(PaperQuestion::getQuestionId, questionId)
    //                     .eq(PaperQuestion::getPaperId, competeExam.getPaperId()).one();
    //             if (question.getType() == 2) {
    //                 // 获取题目的正确答案列表
    //                 List<QuestionAnswer> correctAnswers = questionAnswerService.lambdaQuery().eq(QuestionAnswer::getIsRight, 1).eq(QuestionAnswer::getQuestionId, question.getId()).list();
    //                 // 获取用户的答案列表
    //                 List<UserAnswer> userAnswers = longUserAnswer.stream().map(Pair::getValue).filter(a -> a.getQuestionId().equals(question.getId())).collect(Collectors.toList());
    //
    //                 // 将答案ID排序并比较
    //                 List<Long> correctAnswerIds = correctAnswers.stream().map(QuestionAnswer::getId).sorted().collect(Collectors.toList());
    //                 List<Long> userAnswerIds = userAnswers.stream().map(UserAnswer::getAnswerId).sorted().collect(Collectors.toList());
    //
    //                 // 如果答案完全匹配，则加分
    //                 if (correctAnswerIds.equals(userAnswerIds)) {
    //                     sum += paperQuestion.getScore();
    //                 }
    //             } else  {
    //                 UserPaperAnswer userPaperAnswer = userPaperAnswer2.get(0);
    //                 if (userPaperAnswer.getAnswerId().equals(questionAnswer.getId()) && questionAnswer.getIsRight().equals(1)) {
    //                     sum += paperQuestion.getScore();
    //                 }
    //             }
    //         }
    //     }
    //     userPaper.setTotalScore(sum);
    //     userPaper.setState("submit");
    //     userPaperService.updateById(userPaper);
    //     Calendar cl = Calendar.getInstance();
    //     cl.setTimeInMillis(System.currentTimeMillis());
    //     int userTime = (int) ((System.currentTimeMillis() - userPaper.getCreateTime().getTime()) / 1000 / 60);
    //     UserPaperVo userPaperVo = UserPaperVo.objToVo(userPaper);
    //     userPaperVo.setUserTime(userTime);
    //     return userPaperVo;
    // }
}




